package com.steak.javase.optional;

import com.steak.javase.common.Education;
import com.steak.javase.common.Family;
import com.steak.javase.common.UserInfo;
import com.steak.javase.common.UserVO;

import java.util.Date;
import java.util.Optional;

/**
 * @author 刘牌
 * @date 2022-03-2921:52
 */
public class OptionalTest {
    public static Date getGraduationTime(UserInfo userInfo){
        if (null != userInfo){
            if (null != userInfo.getEducation()){
                return userInfo.getEducation().getGraduationTime();
            }
        }
        return null;
    }

    public static void main(String[] args) {
        UserInfo userInfo = getUser();
        Date graduationTime = getGraduationTime(userInfo);
        System.out.println(graduationTime);

       UserVO user = new UserVO();
//        user.setUsername(userInfo.getName()).setUserAge(userInfo.getAge())
//                .setEdu(userInfo.getEducation().getEducation())
//                .setSchool(userInfo.getEducation().getSchoolName())
//                .setAdmissionDate(userInfo.getEducation().getAdmissionTime())
//                .setGraduationDate(userInfo.getEducation().getGraduationTime())
//                .setFather(userInfo.getFamily().getFatherName())
//                .setMother(userInfo.getFamily().getMotherName());

//        if (null != userInfo){
//            user.setUsername(userInfo.getName()).setUserAge(userInfo.getAge());
//            if (null != userInfo.getEducation()){
//                user.setEdu(userInfo.getEducation().getEducation())
//                        .setSchool(userInfo.getEducation().getSchoolName())
//                        .setAdmissionDate(userInfo.getEducation().getAdmissionTime())
//                        .setGraduationDate(userInfo.getEducation().getGraduationTime());
//            }
//            if (null != userInfo.getFamily()){
//                user.setFather(userInfo.getFamily().getFatherName())
//                        .setMother(userInfo.getFamily().getMotherName());
//            }
//        }

        Optional.ofNullable(userInfo).ifPresent(userInfoI -> {
            user.setUsername(userInfoI.getName()).setUserAge(userInfoI.getAge());
            Optional.ofNullable(userInfoI.getFamily()).ifPresent(family -> {
                user.setFather(family.getFatherName()).setMother(family.getMotherName());
            });
            Optional.ofNullable(userInfoI.getEducation()).ifPresent(education -> {
                user.setEdu(education.getEducation())
                        .setSchool(education.getSchoolName())
                        .setAdmissionDate(education.getAdmissionTime())
                        .setGraduationDate(education.getGraduationTime());
            });
        });
//        System.out.println(user);

    }

    public static UserInfo getUser(){
        Family family = new Family().setFatherName("father")
                .setMotherName("mother");
        Education education = new Education().setEducation("本科")
                .setSchoolName("家里蹲大学")
                .setAdmissionTime(new Date())
                .setGraduationTime(new Date());
        return new UserInfo()
                .setName("小四哥")
                .setAge(24)
                .setEducation(education);
    }
}
